package com.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.beans.Admin;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.beans.Message;
import com.service.impl.MessageServiceImpl;


@Controller
@RequestMapping("/message")
public class MessageController {
    @Resource
    MessageServiceImpl service;

    @RequestMapping("/getmessage")
    public String get(String name, ModelMap model) {
        System.out.println("get==>" + name);
        if (name != null && !name.equals("")) {
            List<Message> list = service.getMessage(name);
            model.addAttribute("list", list);
            return "message/allmessage";
        }
        model.addAttribute("error", "未查询到响应的数据，请您检查输入的数据名称是否正确~");
        System.err.println("error");
        return "message/allmessage";
    }

    @RequestMapping("/getallmessage")
    public String getallMessage(ModelMap m) {
        List<Message> list = service.getAllMessage();
        m.put("list", list);
        return "message/allmessage";
    }



    @RequestMapping("/g")
    public String gotoaddmessag(ModelMap m) {
        List<Message> list = service.getAllMessage();
        m.put("list", list);
        return "message/message";
    }

    /***************** 【以下为修改部分内容】 *********************/

    @RequestMapping("/queryByPage")
    @ResponseBody
    public Map<String, Object> queryByPage(Message message, Integer page, Integer limit) {
        return service.queryByPage(message, page, limit);
    }

    @PostMapping("/addmessage")
    @ResponseBody
    public Integer addMessage(@RequestBody Message message) {
        return service.addMessage(message);
    }

    @PostMapping("/gotoupdatemessage")
    @ResponseBody
    public Integer updateu(@RequestBody Message message) {
        return service.updateMessage(message);
    }

    @RequestMapping("/deletemessage")
    @ResponseBody
    public Integer deleteu(int id) {
        return service.deleteMessage(id);
    }
}
